<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js条件判断之if</title>

</head>
<body>
  <input type="password" name="password">
  <hr>
  <span name="msg"></span>
  <script>
    function query(name) {
      return document.querySelector(`[name="${name}"]`)
    }
    query('password').addEventListener('keyup', function () {
      const length = this.value.trim().length
      const msg = query('msg')
      if (length >= 10) {
        msg.innerHTML = '密码非常安全'
      } else if (length >= 6) {
        msg.innerHTML = '密码安全'
      } else if (length > 0){
        msg.innerHTML = '密码简单'
      } else {
        msg.innerHTML = ''
      }
    })
  </script>
</body>
</html>